package per.ethan.cloud.provider.controller;

import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;
import per.ethan.cloud.common.domain.Page;
import per.ethan.cloud.common.domain.ResultBean;
import per.ethan.cloud.provider.entity.Balance;
import per.ethan.cloud.provider.service.BalanceService;

import java.util.List;
import java.util.Map;

/**
* @author Ethan
* @date 2020/03/11 16:15
*/
@RestController
@RequestMapping("/balance")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class BalanceController{

    @Qualifier("balanceService")
    private final BalanceService balanceService;

    @PostMapping
    @ApiOperation(value = "保存实体信息")
    public ResultBean<Long> saveBalance(@RequestBody Balance balance){
        return ResultBean.success(balanceService.save(balance));
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "通过id查询信息")
    public ResultBean<Balance> findById(@PathVariable Long id){
        return ResultBean.success(balanceService.findById(id));
    }

    @PostMapping("/page")
    @ApiOperation(value = "分页查询")
    public ResultBean<Page<Balance>> findByPage(@RequestBody Page<Balance> page) {
        return ResultBean.success(balanceService.findByPage(page));
    }

    @GetMapping("/getByWhere")
    @ApiOperation(value = "按条件查询信息")
    public ResultBean<List<Balance>> findByWhere(@RequestParam Map<String, Object> paramMap) {
        return ResultBean.success(balanceService.findByMap(paramMap));
    }

    @PutMapping
    @ApiOperation(value = "修改实体信息")
    public ResultBean<Boolean> modify(@RequestBody Balance balance) {
        return ResultBean.success(balanceService.update(balance));
    }

    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除实体信息")
    public ResultBean<Boolean> removeById(@PathVariable Long id){
        return ResultBean.success(balanceService.logicDeleteById(id));
    }

    @DeleteMapping("/batchRemove")
    @ApiOperation(value = "批量删除实体信息")
    public ResultBean<Boolean> batchRemove(@RequestBody List<Long> idList){
        return ResultBean.success(balanceService.logicBatchDelete(idList));
    }

}
